home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_065 / menubuilder / menu.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  183 lines

  1. /* menu test driver program */
  2.  
  3. #include "exec/types.h"
  4. #include "intuition/intuition.h"
  5. #include "graphics/display.h"
  6. #include "libraries/dos.h"
  7. #include "stdio.h"
  8.  
  9. struct IntuitionBase *IntuitionBase;
  10. struct GfxBase *GfxBase;
  11.  
  12. extern struct Menu *MyMenu;
  13.  
  14. struct NewScreen NewScreen =
  15.   {
  16.   0,0,640,200,         /* Left, Top, Width, Height */
  17.   2,0,1,               /* Depth, detail Pen, Block Pen*/
  18.   HIRES,               /* Hi resolution screen */
  19.   CUSTOMSCREEN,        /* type */
  20.   NULL,                /* Font */
  21.   "Custom Services"    /* Screen Title */
  22.   };
  23.  
  24. struct NewWindow NewWindow =
  25.   {
  26.   0, 0, 640, 200,       /* Left edge, Top edge, width, height */
  27.   0, 1,                   /* Width, Height */
  28.   CLOSEWINDOW | MENUPICK, /* IDCMP message flags */
  29.   WINDOWCLOSE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH |
  30.   SMART_REFRESH | ACTIVATE | NOCAREREFRESH,
  31.   NULL,                    /* First Gadget */
  32.   NULL,                    /* default to checkmark */
  33.   "Menu Test Window",      /* Title of window      */
  34.   NULL,                    /* Standard Screen      */
  35.   NULL,                    /* Bit Map              */
  36.   100,  25,                /* Min Width, Min height*/
  37.   640, 200,                /* Max width, Height    */
  38.   CUSTOMSCREEN             /* Screen type          */
  39.   };
  40.  
  41.   int Flgs[26];          /* one flag for each letter */
  42.  
  43. main(argc, argv)
  44.   int argc;
  45.   char **argv;
  46.   {
  47.   unsigned char str[30]; /* window message structure */
  48.   unsigned int i;        /* loop counter */
  49.   unsigned M0, I0, S0;   /* Menu control index */
  50.   struct Screen *Screen; /* ptr to screen*/
  51.   struct Window *Window; /* ptr to window*/
  52.   struct IntuiMessage *message; /*message pointer */
  53.  
  54.   Do_Arguments(argc,argv);
  55.   Delay(150);
  56.  
  57. /* open libraries, screen, and window */
  58.  
  59.   IntuitionBase = (struct IntuitionBase *)
  60.           OpenLibrary("intuition.library",0);
  61.   if( IntuitionBase == NULL )
  62.     {
  63.     printf("Unable to Open intuition.library");
  64.     exit(10);
  65.     };
  66.  
  67.   GfxBase = (struct GfxBase *)
  68.           OpenLibrary("graphics.library",0);
  69.   if( GfxBase == NULL )
  70.     {
  71.     printf("Unable to Open graphics.library");
  72.     exit(10);
  73.     };
  74.  
  75.   if( (Screen = (struct Screen *)OpenScreen(&NewScreen))==NULL)
  76.     {
  77.     printf("Unable to open Screen");
  78.     exit(10);
  79.     };
  80.  
  81.   NewWindow.Screen = Screen;
  82.  
  83.   if( (Window = (struct Window *)OpenWindow(&NewWindow))==NULL)
  84.     {
  85.     CloseScreen(Screen);
  86.     printf("Unable to open window");
  87.     exit(10);
  88.     }
  89.  
  90.   SetMenuStrip(Window, MyMenu);
  91.  
  92.   Move(Window->RPort,20,20);         /* Move text pointer in window */
  93.   Text(Window->RPort,"Hello Sir",9); /* set hello in the window */
  94.   for (;;)  /* loop untill a Close Gadget is struck */
  95.     {
  96.     WaitPort(Window->UserPort);  /* wait for a message */
  97.     message = (struct IntuiMessage *)GetMsg(Window->UserPort);
  98.     if( (message->Class) == MENUPICK ) /* is it a menu message?*/
  99.       {
  100.       for (i=0; i < 30; str[i++] = ' ');
  101.       if( (message->Code) != MENUNULL)
  102.         {
  103.         M0 = MENUNUM(message->Code);
  104.         I0 = ITEMNUM(message->Code);
  105.         S0 = SUBNUM(message->Code);
  106.         if( Flgs[3] )
  107.           {
  108.           sprintf(str,"Menu %x, Item %x, Sitem  %x ",
  109.                           M0, I0, S0);
  110.           Move(Window->RPort, 5, 20);
  111.           Text(Window->RPort, str, 24);
  112.           }
  113.         else
  114.           {
  115.           Process_Item(M0, I0, S0);
  116.           };
  117.         }
  118.       else if ( Flgs[3] )
  119.         {
  120.         sprintf(str,"No Item Selected.       ");
  121.         Move(Window->RPort, 5, 20);
  122.         Text(Window->RPort, str, 24);
  123.         };
  124.       ReplyMsg(message);
  125.       }
  126.     else
  127.       {
  128.       if ( !Flgs[3] )
  129.         {
  130.         M0 = -1;
  131.         I0 = 0;
  132.         S0 = 0;
  133.         Process_Item(M0, I0, S0);
  134.         };
  135.       break; /* Not Menu selection, must be close gadget */
  136.       };
  137.     };
  138.  
  139.   ReplyMsg(message);         /* Reply to message */
  140.   ClearMenuStrip(Window);    /* Remove Menu */
  141.   CloseWindow(Window);       /* close window */
  142.   CloseScreen(Screen);       /* remove the screen */
  143.   exit(TRUE);                /* Good Bye */
  144.   }
  145.  
  146. Do_Arguments(count,strings)
  147.   int count;
  148.   char *strings[];
  149.   {
  150.   register int loop;
  151.   register char *ptr;
  152.   int  c;
  153.  
  154.   if ( count == 2 && *strings[1] == '?' )
  155.     {
  156.     printf(" Usage is: %s [-option ... -option]\n",strings[0]);
  157.     }
  158.   else
  159.     {
  160.     for(loop=0; loop < 26; loop++) Flgs[loop] = FALSE;
  161.     while ( --count > 0 )                       
  162.       {
  163.       ptr = *++strings;
  164.       if ( *ptr++ == '-' )
  165.         {
  166.         c = toupper(*ptr) - 'A' ;  /* get an index 0 to 25 */
  167.         if ( c >= 0 && c <= 25 )
  168.           {
  169.           Flgs[c] = TRUE;
  170.           }
  171.         else
  172.           {
  173.           printf(" %s has an invalid option: %s\n",strings[0],ptr);
  174.           };
  175.         }
  176.       else
  177.         {
  178.         printf(" irregular switch[%d] value:%s\n",count,ptr);
  179.         };
  180.       };
  181.     };
  182.   }
  183.